<template>
    <div class="manageClass">
        <el-upload
        :class="{disabled:uploadDisabled}"
        :action="el_action"
        list-type="picture-card"
        :file-list="fileList"
        :before-upload="handlePictureCardBefore"
        :on-success="handlePictureCardSuccess"
        :on-error="handlePictureCardError"
        :before-remove = "handlePictureCardRemove"
        >
            <i class="el-icon-plus"></i>
        </el-upload>
    </div>
</template>
<script>
export default {
    name:"managePublicUpload",
    props:{
        el_action:[String],
        el_loadUrl:[String]
    },
    data(){
        return{
            uploadDisabled:false,
            fileList:[]
        }
    },
    computed:{
        get_loadUrl(){
            if(this.el_loadUrl != null && this.el_loadUrl != ""){
                this.fileList.length = 0;
                let data = {
                    url:this.el_loadUrl
                }
                this.fileList.push(data);
                this.uploadDisabled = true;
            }else{
                this.fileList.length = 0;
            }
            
        }
    },
    watch:{
        get_loadUrl(){}
    },
    beforeDestroy() {
        console.log("zhix")
        this.fileList.length = 0;
        this.uploadDisabled = false;
    },

    methods:{
        // 图片上传
        handlePictureCardBefore(file){
            this.uploadDisabled = true;
            console.log("上传前",file)
        },
        handlePictureCardSuccess(response, file) {
            console.log("上传成功",response,file)
            this.$message({
                message: response.msg,
                type: 'success'
            });
            this.$emit("el_getlogoUrl",response.data)
            // this.ruleForm.logoUrl = response.data;
        },
        handlePictureCardError(err,file, fileList) {
            console.log("上传失败",err)
            this.$message({
                message: err,
                type: 'error'
            });
        },
        handlePictureCardRemove(){
            console.log("删除")
            this.uploadDisabled = false;
        }
    },
}
</script>
<style>
/* .disabled .el-upload--picture-card {
    display: none;
} */
</style>